Go: Explicitly check whether proxy env vars are empty#19598
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refines proxy environment variable handling to explicitly ignore empty string values, ensuring that unintentionally set empty vars are treated as unset.
- Added
&& var != ""checks to skip empty proxy env vars for host, port, CA certificate, and URLs. - Maintains existing formatting of proxy address and logging only when both host and port are non-empty.
Comment on lines
+53
to
+54
| if proxy_host, proxy_host_set := os.LookupEnv(PROXY_HOST); proxy_host_set && proxy_host != "" { | ||
| if proxy_port, proxy_port_set := os.LookupEnv(PROXY_PORT); proxy_port_set && proxy_port != "" { |
There was a problem hiding this comment.
[nitpick] The pattern of checking for both existence and non-empty value is repeated across multiple env vars. Consider creating a helper such as lookupNonEmptyEnv(key string) (string, bool) to encapsulate this logic and reduce duplication.
Suggested change
| if proxy_host, proxy_host_set := os.LookupEnv(PROXY_HOST); proxy_host_set && proxy_host != "" { | |
| if proxy_port, proxy_port_set := os.LookupEnv(PROXY_PORT); proxy_port_set && proxy_port != "" { | |
| if proxy_host, _ := lookupNonEmptyEnv(PROXY_HOST); proxy_host != "" { | |
| if proxy_port, _ := lookupNonEmptyEnv(PROXY_PORT); proxy_port != "" { |
| } | ||
|
|
||
| if proxy_urls, proxy_urls_set := os.LookupEnv(PROXY_URLS); proxy_urls_set { | ||
| if proxy_urls, proxy_urls_set := os.LookupEnv(PROXY_URLS); proxy_urls_set && proxy_urls != "" { |
There was a problem hiding this comment.
Values containing only whitespace will pass the != "" check and may cause parsing errors. Consider using strings.TrimSpace(proxy_urls) before testing for emptiness to treat whitespace-only inputs as empty.
Suggested change
| if proxy_urls, proxy_urls_set := os.LookupEnv(PROXY_URLS); proxy_urls_set && proxy_urls != "" { | |
| if proxy_urls, proxy_urls_set := os.LookupEnv(PROXY_URLS); proxy_urls_set && strings.TrimSpace(proxy_urls) != "" { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This should resolve github/codeql-action#2909 after we didn't catch this in #19248. If the environment variables are set, but contain the empty string, then we treat those empty strings as meaningful values, even though they are not.